<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-9-21
 * Time: 下午5:54
 */
include('/var/www/html/new/d/module/api/function.class.php');
if (!class_exists("go_sql")){
    include("/var/www/html/new/conf/le.je");
    $le=new go_sql();
    $le->connect();
}
$txt1=  json_encode($_REQUEST);
logfile(date('Y-m-d,H:i:s').$txt1);

//print_r($_REQUEST['order_id']);
$order_id   = $_REQUEST['order_id'];
$cust_id    = $_REQUEST['cust_id'];
$apikey     = $_REQUEST['apikey'];
$finish_num = $_REQUEST['finish_num'];
if(empty($_REQUEST['order_id'])){

exit('fail');
}else{

        $PFT_infunction = new AllFunction();

    $str="select pftOrder from all_api_order where apiOrder='".$_REQUEST['order_id'] ."' limit 1";
        $GLOBALS['le']->query($str);

        $GLOBALS['le']->fetch_assoc();
        $pftOrder  = $GLOBALS['le']->f('pftOrder');
        $pft_order_xml = $PFT_infunction->Select_PFTorder($pftOrder);

        $UUsalerid  = (string)$pft_order_xml->Rec->UUsalerid;
        $UUcode  = (string)$pft_order_xml->Rec->UUcode;
        $terminal = $PFT_infunction->Compatible_Check_IN($UUsalerid,$UUcode,date('Y-m-d H:i:s'));
        if($terminal  == 100){
            $str="update all_api_order set oStatus=1,handleStatus=0 where pftOrder='".$pftOrder."' limit 1";
            $GLOBALS['le']->query($str);
            logfile($pftOrder.'|'.$_REQUEST['order_id'].'|'.$terminal,'terminalCheck_success');
            echo 'true';
        }
        else{
            logfile($pftOrder.'|'.$_REQUEST['order_id'].'|'.$terminal,'terminalCheck_fail');
            echo 'fail';
        }

    }



    function logfile($txt){
        $fp = fopen( '/var/www/html/new/d/module/qkxproject/api/ziwoyou/pushInfo.txt', "a");
        flock($fp, LOCK_EX);
        fwrite($fp, $txt . "\n");
        flock($fp, LOCK_UN);
        fclose($fp);
    }